//
//  CYDiscoveryHttpTool.m
//  CreditAddressBook
//
//  Created by LE on 15/12/18.
//  Copyright © 2015年 Lee. All rights reserved.
//

#import "CYDiscoveryHttpTool.h"
#import "CYCarInfo.h"
#import "MJExtension.h"
#import "CYJsonInfo.h"
#import "LEProgressButton.h"
#import "CYCarCompanyAccount.h"
#import "CYCarUserAccount.h"
#import "CYUserAccount.h"
#import "CYCompanyUserTool.h"
#import "CYSimpleRecord.h"
#import "CYSimpleLoanM.h"
#import "CYSimpleRewardM.h"

@implementation CYDiscoveryHttpTool


/*!
 *  @brief  车贷联盟申诉
 */
+ (void)handleAppealWithParam:(NSDictionary *)param success:(void(^)(NSString *message))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].handleAppeal params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"车贷联盟申诉错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}
/**
 *  公司资金总账表
 */
+ (void)getCompanyAccountBalanceWithParam:(NSDictionary *)param success:(void(^)(CYCompanyAccount *userAccount))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].getCompanyAccountBalance params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                CYCompanyAccount *userAccount = [CYCompanyAccount objectWithKeyValues:jsonInfo.data];
                success(userAccount);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取用户帐户信息失败: %@", error);
        if (failure) {
            failure(@"服务器连接错误", YES);
        }
    }];
}

/*!
 *  @brief  查看自己申请的悬赏
 */
+ (void)getOwnRewoardWithParam:(NSDictionary *)param success:(void(^)(NSArray *simpleList))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].getOwnRewoard params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                NSArray *simples = [CYSimpleLoanM objectArrayWithKeyValuesArray:jsonInfo.data];
                success(simples);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"查看自己申请的悬赏错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}

/*!
 *  @brief  我的发布悬赏处理，取消支付
 */
+ (void)cancelPayWithParam:(NSDictionary *)param success:(void(^)(NSString *message))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].cancelPay params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"我的发布取消支付错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}


/*!
 *  @brief  企业处理查询结果,悬赏处理
 */
+ (void)payApplyWithParam:(NSDictionary *)param success:(void(^)(NSString *message))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].payApply params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"悬赏处理错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}


/*!
 *  @brief  企业处理查询结果,悬赏处理
 */
+ (void)handleRewardWithParam:(NSDictionary *)param success:(void(^)(CYCarRewardApplyM *carRewardApply))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].handleReward params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                CYCarRewardApplyM *model = [CYCarRewardApplyM objectWithKeyValues:jsonInfo.data];
                success(model);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"悬赏处理错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}

/*!
 *  @brief  申请悬赏
 */
+ (void)saveRewordWithParam:(NSDictionary *)param success:(void(^)(NSString *message))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].saveReword params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"申请悬赏错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}


/*!
 *  @brief  获取展示
 */
+ (void)getDisplayWithParam:(NSDictionary *)param success:(void(^)(BOOL isDisplay, BOOL isPay))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].getDisplay params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            NSString *display = jsonInfo.data[@"display"];
            NSString *pay = jsonInfo.data[@"pay"];
            if (success) {
                success(display.boolValue, pay.boolValue);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取展示错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}


/*!
 *  @brief  获取此企业录入的loan
 */
+ (void)getLoanListByCompanyWithParam:(NSDictionary *)param success:(void(^)(NSArray *simpleList))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].getLoanListByCompany params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                NSArray *simples = [CYSimpleLoanM objectArrayWithKeyValuesArray:jsonInfo.data];
                success(simples);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取此企业录入的loan错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}

/*!
 *  @brief  车贷联盟企业版获取查询结果
 */
+ (void)getLoanSearchWithParam:(NSDictionary *)param success:(void(^)(NSArray *simpleList))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].getLoanSearch params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                NSArray *simples = [CYSimpleLoanM objectArrayWithKeyValuesArray:jsonInfo.data];
                success(simples);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"车贷联盟企业版获取查询结果错误: %@", error);
        if (failure) {
            failure(@"网络错误", YES);
        }
    }];
}


/*!
 *  @brief  车贷联盟首页数据查询
 */

+ (void)simpleLoanListWithParam:(NSDictionary *)param success:(void(^)(CYSimpleLoanRewardM *reward, NSArray *simpleList, NSArray *rewardList))success failure:(HttpRequestFailure1)failure {
    [CYHttpTool postWithURL:[CYURL shared].simpleLoanList params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                CYSimpleLoanRewardM *simple = [CYSimpleLoanRewardM objectWithKeyValues:jsonInfo.data[@"reward"]];
                NSArray *simples = [CYSimpleLoanM objectArrayWithKeyValuesArray:jsonInfo.data[@"simpleList"]];
                NSArray *rewards = [CYSimpleRewardM objectArrayWithKeyValuesArray:jsonInfo.data[@"rewardList"]];
                success(simple, simples, rewards);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"车贷联盟首页数据查询错误: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}



+ (void)addCarInfoWithParam:(CYCarInfo *)carInfo success:(void(^)(NSString *message))success failure:(HttpRequestFailure1)failure {
    NSMutableDictionary *carInfoDic = carInfo.keyValues;
    [CYHttpTool postWithURL:[CYURL shared].addCarInfo params:carInfoDic success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"添加车辆错误: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}

+ (void)checkPlateNumberWithPlateNumber:(NSString *)number success:(void(^)(NSString *message))success failure:(HttpRequestFailure1)failure {
    NSDictionary *param = @{@"plateNumber": number};
    [CYHttpTool postWithURL:[CYURL shared].checkPlateNumber params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"检查车牌号出错: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}

+ (void)carInfoListWithParam:(NSDictionary *)param success:(void(^)(NSArray *cars))success failure:(HttpRequestFailure1)failure {
    [CYHttpTool postWithURL:[CYURL shared].carInfoList params:param success:^(id json) {
        CYJsonInfo *jsoInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsoInfo.isSuccess) {
            NSArray *arr = jsoInfo.data;
            if (arr && arr.count) {
                arr = [CYCarInfo objectArrayWithKeyValuesArray:arr];
            }
            if (success) {
                success(arr);
            }
        } else {
            if (failure) {
                failure(jsoInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取车辆列表错误: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}

+ (void)addCarRentalWithParam:(CYCarRental *)carInfo success:(void(^)(NSString *message))success failure:(HttpRequestFailure1)failure {
    NSMutableDictionary *carInfoDic = carInfo.keyValues;
    [CYHttpTool postWithURL:[CYURL shared].addCarRental params:carInfoDic success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"添加租车信息错误: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}

+ (void)getCarCompanyAccountByCompanyIdWithParam:(NSDictionary *)param success:(void(^)(CYCarCompanyAccount *account))success failure:(HttpRequestFailure1)failure {
    [CYHttpTool postWithURL:[CYURL shared].getCarCompanyAccountByCompanyId params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                CYCarCompanyAccount *account = [CYCarCompanyAccount objectWithKeyValues:jsonInfo.data];
                success(account);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取企业租车风险金帐户信息失败: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}

+ (void)getCarUserAccountByUserIdWithParam:(NSDictionary *)param success:(void(^)(CYCarUserAccount *account))success failure:(HttpRequestFailure1)failure {
    [CYHttpTool postWithURL:[CYURL shared].getCarUserAccountByUserId params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                CYCarUserAccount *account = [CYCarUserAccount objectWithKeyValues:jsonInfo.data];
                success(account);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取用户租车风险金帐户信息失败: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}

+ (void)getCompanyCarRewardWithParam:(NSDictionary *)param success:(void(^)(NSNumber *account, NSNumber *riskAccount))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].getCompanyCarReward params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                NSNumber *account = jsonInfo.data[@"carCompanyAccountBalance"];
                NSNumber *riskAccount = jsonInfo.data[@"limit"];
                success(account, riskAccount);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取企业用户租车风险金帐户信息失败: %@", error);
        if (failure) {
            failure(@"网络异常", YES);
        }
    }];
}

+ (void)getUserCarRewardWithParam:(NSDictionary *)param success:(void(^)(NSNumber *account, NSNumber *riskAccount))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].getUserCarReward params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                NSNumber *account = jsonInfo.data[@"carUserAccountBalance"];
                NSNumber *riskAccount = jsonInfo.data[@"limit"];
                success(account, riskAccount);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取用户租车风险金帐户信息失败: %@", error);
        if (failure) {
            failure(@"服务器连接异常", YES);
        }
    }];
}


+ (void)getUserAccountBalanceWithParam:(NSDictionary *)param success:(void(^)(CYUserAccount *userAccount))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].getUserAccountBalance params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                CYUserAccount *userAccount = [CYUserAccount objectWithKeyValues:jsonInfo.data];
                success(userAccount);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取用户帐户信息失败: %@", error);
        if (failure) {
            failure(@"服务器连接错误", YES);
        }
    }];
}

+ (void)carRentalListWithParam:(NSDictionary *)prama userType:(CYCarStatusType)type success:(void(^)(NSArray *carRentalList))success failure:(HttpRequestFailure1)failure {
    [CYHttpTool postWithURL:[CYURL shared].carRentalList params:prama success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                NSArray *carRentalList = [CYCarRental objectArrayWithKeyValuesArray:jsonInfo.data];
                NSMutableArray *arr = [NSMutableArray array];
                for (CYCarRental *carRental in carRentalList) {
                    if (carRental.status.integerValue == type) {
                        [arr addObject:carRental];
                    }
                }
                success(arr);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"获取企业租车风险金帐户信息失败: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}

+ (void)updateStatusWithParam:(NSDictionary *)carRental success:(void(^)(NSString *message))success failure:(HttpRequestFailure1)failure {
    [CYHttpTool postWithURL:[CYURL shared].updateStatus params:carRental success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"还车失败: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}

+ (void)getCarInfoByPlateNumberWithPlateNumber:(NSString *)plateNumber success:(void(^)(CYCarInfo *carInfo))success failure:(HttpRequestFailure1)failure {
    NSDictionary *param = @{@"plateNumber": plateNumber};
    [CYHttpTool postWithURL:[CYURL shared].getCarInfoByPlateNumber params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                CYCarInfo *account = [CYCarInfo objectWithKeyValues:jsonInfo.data];
                success(account);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, nil);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"根据车牌查询车辆信息失败: %@", error);
        if (failure) {
            failure(nil, error);
        }
    }];
}
/**
 *  根据身份证号码或电话号码或车牌号码查询
 *
 *  @param param
 *  @param success
 *  @param failure
 */
+ (void)creditQueryWithParam:(NSDictionary *)param success:(void(^)(NSString *html))success failure:(HttpRequestFailure2)failure {
//    NSString *url = [CYURL shared].creditQuery;
//    url = [url appendingString:@"?condition=530302199302091213"];
//    [CYHttpTool getWithURL:url params:nil success:^(id json) {
//        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
//        if (jsonInfo.isSuccess) {
//            if (success) {
////                CYCarInfo *account = [CYCarInfo objectWithKeyValues:jsonInfo.data];
////                success(account);
//            }
//        } else if (jsonInfo.isNoLogin) {
//            if (failure) {
//                failure(kCYLoginStatusError, NO);
//            }
//        } else {
//            if (failure) {
//                failure(jsonInfo.message, YES);
//            }
//        }
//    } failure:^(NSError *error) {
//        CYLog(@"根据车牌查询车辆信息失败: %@", error);
//        if (failure) {
//            failure(@"服务器连接错误", YES);
//        }
//    }];
    [CYHttpTool postSerializerWithURL:[CYURL shared].creditQuery params:param success:^(id data) {
        if (data) {
            NSString *html = [[NSString alloc] initWithData:data  encoding:NSUTF8StringEncoding];
            if (success) {
                success(html);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"根据车牌查询车辆信息失败: %@", error);
        if (failure) {
            failure(@"服务器连接错误", YES);
        }
    }];
}
/**
 *  租车风险金帐号充值
 *
 *  @param param
 *  @param success
 *  @param failure
 */
+ (void)carUserAccountRechargeWithParam:(NSDictionary *)param success:(void(^)(NSString *message))success failure:(HttpRequestFailure2)failure {
    [CYHttpTool postWithURL:[CYURL shared].carUserAccountRecharge params:param success:^(id json) {
        CYJsonInfo *jsonInfo = [CYJsonInfo objectWithKeyValues:json];
        if (jsonInfo.isSuccess) {
            if (success) {
                success(jsonInfo.message);
            }
        } else if (jsonInfo.isNoLogin) {
            if (failure) {
                failure(kCYLoginStatusError, NO);
            }
        } else {
            if (failure) {
                failure(jsonInfo.message, YES);
            }
        }
    } failure:^(NSError *error) {
        CYLog(@"租车风险金帐号充值失败：%@", error);
        if (failure) {
            failure(@"服务器连接错误", YES);
        }
    }];
}

+ (void)uploadUserImage:(UIImage *)image button:(LEProgressButton *)btn success:(void (^)(NSString *imagePath))success failure:(HttpRequestFailure1)failure {
    [btn setImage:image forState:UIControlStateNormal];
    [CYHttpTool postWithURL:[CYURL uploadPicPath] params:nil image:image success:^(id json) {
        //上传成功更新图片访问路径
        if ([json[@"success"] isEqualToString:@"success"]) {
//            btn.ratio = 1;
            if (success) {
                success(json[@"message"]);
            }
        } else {
//            btn.ratio = -1;
            if (failure) {
                failure(json[@"message"], nil);
            }
            //清除图片显示数据
            [btn setImage:[UIImage imageNamed:@"未标题-5"] forState:UIControlStateNormal];
        }
    } failure:^(NSError *error) {
        CYLog(@"头像上传用户服务器连接失败：%@", error);
//        btn.ratio = -1;
        if (failure) {
            failure(nil, error);
        }
        //清除图片显示数据
        [btn setImage:[UIImage imageNamed:@"未标题-5"] forState:UIControlStateNormal];
    } uploadProgress:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
        //        CYLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
//        CGFloat a = totalBytesWritten;
//        CGFloat b = totalBytesExpectedToWrite;
//        btn.ratio = a/b - 0.01;
    }];
}
@end
